<?
include("session.php");

// 用于保持session变量; 
if( isset($_GET['session_keeplive']) ) {
    echo "ok";
	exit;
}

// 此页面即来电入口; 
$client_id = 0;
if( isset($_GET['client_id']) ) {
    $client_id =  $_GET['client_id'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/webkit/utils/jquery.js"></script>
<script type="text/javascript" src="/webkit/grid/import.js"></script>
<script type="text/javascript" src="/webkit/dialog/import.js"></script>
<script type="text/javascript" src="/webkit/datepicker/WdatePicker.js"></script>
<link type="text/css" rel="stylesheet" href="page.css"/>
</head>
<body>

<table width=100% height=100% cellspacing=0 cellpadding=0>
	<tr bgcolor="#eeeeee">
	<form name=f>

	<td height=30>&nbsp;
	工单状态：<select id="order_status"><option value=''>-全部-</option><option value=1>待处理</option><option value=2>已派单</option><option value=3>回单</option><option value=4>改约</option></select>　　 
    客户名称：<input type=text id='client_name' size=8 value='<?echo $_GET['client_name']?>'>　
	联系电话：<input type=text id='telephone' size=10 value='<?echo $_GET['telephone']?>'>　

	<span id='more_search_span' style='display:none'> <!--这组条件只有管理可见-->
    受理人：<select id='agent_name'><option value=''>-全部-</option><option value='jx01'>jx01</option><option value='jx02'>jx02</option><option value='jx03'>jx03</option></select>　
	受理时间：<input type="text" id="begin_time" name="begin_time" onClick="WdatePicker({readOnly:true, skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="15"> - <input type="text" id="end_time" name="end_time" onClick="WdatePicker({readOnly:true, skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="15">　
	收单人：<select id='user_name'><option value=''>-全部-</option></select>　<br>&nbsp; 
	回访结果：<select id="callback_result"><option value=''>-全部-</option><option value='1'>非常满意</option><option value='2'>满意</option><option value='3'>一般</option><option value='4'>不满意</option></select>　　　 
	</span>

	<input type="button" value="查询" onclick="search()">　<input type="button" value="导出" onclick="export_excel()">　<input type="button" value="录音查询" onclick="record_search()" style="color:blue">　
	</td>
	</tr>
	<tr>
	<td>
		<table id="flex1" style="display:none"></table>
	</td>
	</form>
	</tr>
</table>
<iframe name=free width=0 height=1></iframe>

<script type="text/javascript">
	
	<?if($_SESSION['user_flag'] == "admin"){?>
	var search_bar_height = 142;  // 管理员角色有两行查询条件
	<?} else {?>
	var search_bar_height = 122;
	<?}?>

	<?if($_SESSION['is_agent']=='yes') {?>
	var h = window.screen.height-(115+search_bar_height+100); // 嵌入到座席框架后，还要多减100的高度
	<?} else {?>
	var h = parent.document.body.clientHeight-(115+search_bar_height);
	if(h < 0) h = 'auto'
	<?}?>
	$("#flex1").flexigrid({
		url: 'order_query.php?action=list&client_id=<?echo $client_id?>',
		dataType: 'json',
		colModel : [
			{display: 'ID', name : 'id', width : 40, sortable : true, align: 'center'},
			{display: '工单号', name : 'a', width : 100, sortable : false, align: 'center'}, 
            {display: '客户名称', name : 'a', width : 60, sortable : false, align: 'center'}, 
			{display: '联系电话', name : 'a', width : 80, sortable : false, align: 'center'},
			{display: '受理座席', name : 'a', width : 50, sortable : false, align: 'center'},
			{display: '受理时间', name : 'call_time', width : 120, sortable : true, align: 'center'},
			{display: '收单工号', name : 'a', width : 50, sortable : false, align: 'center'},
			{display: '回单时限', name : 'expire_time', width : 120, sortable : true, align: 'center'},
			{display: '首次回应', name : 'user_called', width : 50, sortable : true, align: 'center'},
			{display: '催单次数', name : 'hasten_count', width : 50, sortable : true, align: 'center'},
			{display: '工单状态', name : 'a', width : 50, sortable : false, align: 'center'},
			{display: '回访结果', name : 'a', width : 50, sortable : false, align: 'center'},
            {display: '质检结果', name : 'a', width : 50, sortable : false, align: 'center'},
			{display: '联系记录', name : 'a', width : 100, sortable : false, align: 'center'}
			],
		buttons : [
			<?if($_SESSION['user_flag'] == "admin"){?>
			{name: '新增', bclass: 'add', onpress : add},
			<?}?>
			{name: '修改', bclass: 'edit', onpress : edit}
			<?if($_SESSION['uid'] == "admin"){?>
            ,{name: '删除', bclass: 'del', onpress : del}
            <?}?>
		],
		<?if($_SESSION['is_agent'] == "yes"){?>
		//title : '工单列表',
		<?}?>
		async : true,
		usepager: true,
		useRp: true,
		rp: 15,
		showTableToggleBtn: false,
		width: 'auto',
		height: h,
		resizable : false,
		singleSelect : true
	});


	$('#flex1').dblclick( function (e) { 
        select_row_on_dblclick(e);
		edit();
	}); 

	var client_id = <?echo $client_id?>;

	<?
	$add_url = "order_panel.php?op=add";
	if($client_id > 0) $add_url .= "&client_id=$client_id";  // 指定了客户进行新增操作
	$edit_url = "order_panel.php?op=edit&id=";
	$del_url = "order_query.php?action=del&id=";
	$dlg_size = "600,430";
	require("grid_common_js.php");
	?>

	function show_contact_record(tel, begin_time, end_time) {
		dlg = new Dialog({ title: '客户联系记录', resizable:false, maximizable:false}).href("http://222.240.139.227:9080/jinxun/record_file_list.jsp?telephone="+tel+"&begin_time="+begin_time+"&end_time="+end_time);
		dlg.show().setSize(500,200).center();	
	}


	function search() { 
		var url = bind_query_params("order_query.php?action=list");
		$('#flex1').flexOptions({'url': url}).flexReload(); 
	}


	function export_excel() {
		if(confirm('确认将当前记录集导出成Excel吗？')) {
			var url = bind_query_params("order_export.php?format=excel");
			window.frames['free'].location = url;
		}
	}

	function record_search() {
		dlg = new Dialog({ title: '通话录音查询', resizable:false, maximizable:false}).href("record_search.php");
		dlg.show().setSize(650,400).center();	
	}

	function bind_query_params(url) {
		if($("#order_status").val()!="") {
            url += "&order_status="+ $("#order_status").val();
        }      
         if($("#client_name").val()!="") {
            url += "&client_name="+ encodeURI($("#client_name").val());
        }        
		if($("#telephone").val()!="") {
			url += "&telephone="+ $("#telephone").val();
		}
		if($("#agent_name").val()!="") {
			url += "&agent_name="+ $("#agent_name").val();
		}
		if($("#user_name").val()!="") {
			url += "&user_name="+ $("#user_name").val();
		}
		if($("#callback_result").val()!="") {
			url += "&callback_result="+ $("#callback_result").val();
		}  
		if($("#begin_time").val()!="" && $("#end_time").val()!="") {
			url += "&time_range="+ $("#begin_time").val()+"_"+$("#end_time").val();
		} 	
		return url;
	}
	
	var f = document.f;
	$(function() {
			$.get("user_query.php?action=get_select_options", function(data) {
				var arr = data.split("$");
				for(var i=0; i<arr.length; i++){
					var kv = arr[i].split(',');
					f.user_name.options[i+1] = new Option(kv[1], kv[0]);
				}
			});   
			
			<?
			if($_SESSION['user_flag'] == 'admin') { // 全部条件查询只有管理角色可见
			?>
			$('#more_search_span').show();
			<?}?>
	});


	function session_keeplive() {
		$.get("order_list.php?session_keeplive=1", function(data) {
			; // do nothing
		});
		$.getJSON("http://222.240.139.227:9080/jinxun/keep_alive.jsp?callback=?&action=1", function(data) {
			; // do nothing
		});
	}
	window.setInterval("session_keeplive()", 1000 * 60);

</script>
</body>
</html>
